Imports System.Collections.Generic
Imports System.Text
<Record(FieldMapping:=FieldMapping.ExplicitColumnsOnly)> _
Public Class Record
    Implements IDisposable
    Private MyRecordHolder As Core.RecordHolder
    Public Sub New()
#If TRACE Then
        System.Diagnostics.Trace.WriteLine("New " & Me.[GetType]().Name)
#End If
    End Sub
    Public Function GetField(ByVal index As Integer) As Object
        Return MyRecordHolder.GetRecordField(Me, index)
    End Function
    Friend Property RecordHolder() As Core.RecordHolder
        Get
            Return MyRecordHolder
        End Get
        Set(ByVal value As Core.RecordHolder)
#If DEBUG Then
            System.Diagnostics.Debug.Assert(MyRecordHolder Is Nothing, "RecordHolder can only be set once")
#End If
#If TRACE Then
            Dim RecordNum As Integer = value.RecordNo
            System.Diagnostics.Trace.WriteLine(Me.[GetType]().Name + " #" + RecordNum.ToString)
#End If
            MyRecordHolder = value
        End Set
    End Property
    Public ReadOnly Property RecordNo() As Int32
        Get
            Return MyRecordHolder.RecordNo
        End Get
    End Property
    Public Sub SaveChanges()
        MyRecordHolder.SaveChanges(Me)
    End Sub
#Region "   IDisposable Support"
    Private disposedValue As Boolean ' To detect redundant calls

    ' IDisposable
    Protected Overridable Sub Dispose(disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
                MyRecordHolder.OnRecordDisposed(Me)
            End If
        End If
        Me.disposedValue = True
    End Sub
    Protected Overrides Sub Finalize()
        Dispose(False)
        Try
#If DUMP_FINALIZE Then
    			System.Diagnostics.Trace.WriteLine("Entering Destructor " & Me.[GetType]().Name & " #" & Convert.ToString(mHolder.mRecordNo))
#End If
            MyRecordHolder.OnRecordDisposed(Me)
        Finally
            MyBase.Finalize()
        End Try
    End Sub
    Public Sub Dispose() Implements IDisposable.Dispose
        ' Do not change this code.  Put cleanup code in Dispose(disposing As Boolean) above.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub
#End Region
End Class
